
#include "objectsystem.h"
#include "object.h"
#include <stdio.h>
#include <stdlib.h>

#define swapendianword(data) ((data&0xFF00)>>8)+((data&0x00FF)<<8)
inline signed short swapsignedword(unsigned short data){ unsigned short temp=swapendianword(data); if(temp>32767){ return (signed short)temp; } else { return temp; } }
object *FindFreeObj();
bool freeObjects();

extern long v_screenposx;
extern long v_screenposy;

word **ObjPos_Index=new word*[376]; //pointers to level object position array per level
object* objects = new object[127];
object* player=&objects[0];
word objrightcount;
word objleftcount;
byte objstate[376];
word *v_opl_datax1;
word *v_opl_datax2;
word *v_opl_datay1;
word *v_opl_datay2;
signed short v_opl_screen;
int v_opl_routine;
word v_dle_routine;

bool obfree=true;

void printbits(byte n) {
	                     unsigned int i;
                      i = 1<<(sizeof(n) * 8 - 1);

                      while (i > 0) {
		if (n & i)
		{
			//printf("1");
        }
		else
		{
			//printf("0");
        }
		i >>= 1;
	}
}

unsigned int rotl(const unsigned int value, int shift) {
    if ((shift &= sizeof(value)*8 - 1) == 0)
      return value;
    return (value << shift) | (value >> (sizeof(value)*8 - shift));
}
 
unsigned int rotr(const unsigned int value, int shift) {
    if ((shift &= sizeof(value)*8 - 1) == 0)
      return value;
    return (value >> shift) | (value << (sizeof(value)*8 - shift));
}



void OPL_Main(int zone)
{
     	for (int a=32; a<127; a++)
	{
	//printf("objects[%i].X=%i\n",a,objects[a].X);
	//printf("objects[%i].Y=%i\n",a,objects[a].Y);
    //printf("objects[%i].ID=%i\n",a,objects[a].ID);
    }
     ////printf("%i\n",ObjPos_Index);
    int oldstate=0;
    int number=0;
    ////printf("Using this to add to screen: ");
    //scanf("%d", &number);

    v_screenposx=v_screenposx+number;
    v_screenposy=0;
    
	if (v_opl_routine != 2)
	{
        v_screenposx=0;
		//OPL_Main:
		v_opl_routine = 2;
		v_opl_datax1=(ObjPos_Index[zone]);   //pointer to the zones x locations (v_opl_data in rom)
		v_opl_datax2=(ObjPos_Index[zone]);	 //2nd pointer to the zones x locations (v_opl_data+4 in rom)
		v_opl_datay1=(ObjPos_Index[zone])+1;   //pointer to the zones y locations 
		v_opl_datay2=(ObjPos_Index[zone])+1;   //2nd pointer to the zones y locations
		
		//printf ("\nv_opl_datax1=%p",v_opl_datax1);
		//printf ("\nv_opl_datax2=%p",v_opl_datax2);
		//printf ("\nv_opl_datay1=%p",v_opl_datay1);
		//printf ("\nv_opl_datay2=%p",v_opl_datay2);
		
        //signed short t=swapsignedword(*v_opl_datax1);
		////printf ("\n*v_opl_datax1=%i",t);
		
		objleftcount=1;
		objrightcount=1;
		
		//OPL_ClrList:
		for (int lp=0; lp<376; lp++)
			objstate[lp]=0;				//clear pre-destroyed object list
		
		signed short temp=v_screenposx-128; //temp screen x accounting for objects at least 128 pixels off the left edge screen at initial level position
		if (temp < 0)       //if initial screen x pos for this level is < 128 
			temp=0;          //use 0 for screen position
		temp=temp & 0xFF80;	 //scale this value to the nearest unit of 128 pixels (aka if screen x <= 127 screen x = 0 if screen x <= 255 then screen x = 128
		
		int index=0;
		int oldstate=0;
		
		word *xindex=v_opl_datax1;
		word *statusindex=xindex+2;
		signed short xpos=((signed short)swapsignedword(*(xindex)));
		signed char status=((swapsignedword(*(statusindex)) & 0xFF00)>>8);
		int count=0;
		//TEMP < XPOS SKIP
		//TEMP >= XPOS DO
		//XPOS < TEMP DO
		while (xpos < temp && xpos != -1) //for objects 2/5 screens after the left of initial position
		{
   			if (status <= 0) //
			{
				oldstate=objrightcount;        //oldstate = object number
				objrightcount=objrightcount+1; //objstatecount = number of respawning objects
			}
            count++;
            //printf("xpos: %i\n",xpos);
            			
            xindex=xindex+3;                   //address of next object x
            statusindex=statusindex+3;         //address of next object status
              xpos=((signed short)swapsignedword(*(xindex))); //get next obj x
              status=((swapsignedword(*(statusindex)) & 0xFF00)>>8); //get next obj status
        }
	
		v_opl_datax1 = xindex;   //v_opl_datax1 now points to the first object left of screen
		////printf("v_opl_datax1 after parsing through all valid objects (right of initial pos):%i\n", v_opl_datax1);
		//using v_opl_datax2 now
        temp=temp-128;    //now we are 4/5 screens to left of initial position
	
		        
        if (temp >= 0)	//if position at least 4/5 screens into level 
		{
 	        word *xindex=v_opl_datax2;
            word *statusindex=xindex+2;
            signed short xpos=((signed short)swapsignedword(*(xindex)));
            signed char status=((swapsignedword(*(statusindex)) & 0xFF00)>>8);        

            //loc_D964:
			while (xpos < temp && xpos != -1) //for objects 4/5 screens to the left of initial position 
			{
				if (status <= 0) //5th byte=ob id, 8th bit = respawn bit which we check for here
				{
					objleftcount=objleftcount+1;  //add to objects left count
				}
				
			    xindex=xindex+3;                   //address of next object x
                statusindex=statusindex+3;         //address of next object status
                xpos=((signed short)swapsignedword(*(xindex))); //get next obj x
                status=((swapsignedword(*(statusindex)) & 0xFF00)>>8); //get next obj status
        	    //printf("xpos 2: %i\n", xpos);
            
            }
		}
		
		//loc_D976:
		v_opl_datax2=xindex-3;                 //v_opl_datax2 points to end of this buffer now, use in revers
		v_opl_screen=-1;					 //initial position
	}
	
	//OPL_Next:

	signed short temp=v_screenposx & 0xFF80;                 //scale this value to the nearest unit of 128 pixels (aka if screen x <= 127 screen x = 0 if screen x <= 255 then screen x = 128
	word *xindex = v_opl_datax2; 		//points to reverse 2nd x location buffer (objects
	
	////printf("scaled screen at OPL_Next: %i\n", temp);
	////printf("v_opl_screen: %i\n", v_opl_screen);
	
	//debug
	//printf("temp: %i\nv_opl_screen:%i\n",temp,v_opl_screen);
    if (temp != v_opl_screen)    //if not at the same previous screen position 
	{
        //TEMP >= V-OPL-SCREEN SKIP, VOPLSCREEN < TEMP THEN SKIP, IF VOPLSCREEN >= TEMP THEN DO CODE
   		if (v_opl_screen >= temp) //if screen has since moved to the left since last call to this func
		{
            v_opl_screen=temp;	 	//remember current screen position for comparison at next call   
            word *xindex=v_opl_datax2-3;
            word *statusindex=xindex+2;
            signed short xpos=((signed short)swapsignedword(*(xindex-3)));  //grab x pos of previous obj
            signed char status=((swapsignedword(*(statusindex-3)) & 0xFF00)>>8);        
			//printf("v_opl_screen < temp\n");
			//printf("xpos(%i): %i\n", (xindex-3-ObjPos_Index[zone])/3, xpos);
			//printf("status(%i): ", (xindex-3-ObjPos_Index[zone])/3);
			printbits(status);
			//printf("\n");
			
			//*movea.l (v_opl_data+4),a0, aka index=1
			temp=temp-128;		 	//now accounting for objects within 128 pixels of screen x   2/5ths of screen
	     
    		//loc_D9D2
            if (temp >= 0)	                         //if at least 2/5ths of a screen in
			{
				bool freeobjects=true;
	
                //loc D9A6
                while (freeobjects && (((xindex-ObjPos_Index[zone])/3) > 0))
				{
                    freeobjects=freeObjects();   //extra call to this
					xindex=xindex-3;			//since this is backwards it points to the 2nd null index in each group, so make it the first index
					statusindex=statusindex-3;
					xpos=((signed short)swapsignedword(*(xindex)));  //grab x pos of previous obj
                    status=((swapsignedword(*(statusindex)) & 0xFF00)>>8);  
					//printf("xpos(%i): %i\n", (xindex-ObjPos_Index[zone])/3, xpos);
			        //printf("status(%i):", (xindex-ObjPos_Index[zone])/3);
			        printbits(status);
		           	//printf("\n");
			        

					//CMP XPOS, TEMP: BGE SKIPPASTCODE | IF TEMP >= XPOS THEN SKIPPASTCODE | IF TEMP < XPOS THEN DO CODE | IF XPOS >= TEMP THEN DO CODE 
					if (xpos >= temp)
					{
                        if ( status <= 0 ) //5th byte=ob id, 8th bit = respawn bit which we check for here, or if at a null index
    					{
                            objrightcount=objrightcount-1;        //paralell array, working with previous object 
        	                oldstate=objrightcount;              //this object is onscreen now, oldstate is index of this obj
    					}
    				    
                        //loc_D9BC:
                         //bsr locDA3C
                         //=============loc_DA3C==============
    				     bool skip=false;
    				     if ( status <= 0 ) //if this object has the respawn bit
    				     {
                            byte zcode=(objstate[oldstate] & 0x128) >> 7;
    					    objstate[oldstate] = objstate[oldstate] | 0x128; //set bit 8 (respawn bit) of object state buffer, oldstate refers to original object we are working with
    					    if (zcode != 0)                     //if respawn bit already set for this object  
    					    {                 
    						   xindex=xindex+3;
    						   statusindex=statusindex+3;
    						   xpos=((signed short)swapsignedword(*(xindex)));  //grab x pos of previous obj
                               status=((swapsignedword(*(statusindex)) & 0xFF00)>>8);  
    						   skip=true;
    					    }
    						
    	                 }
    				
    					if (skip==false)
    					{
    						object *freeobj;
    						freeobj=FindFreeObj();
    						freeobjects = freeObjects();
    						
    						//OPL_MakeItem
    						if (freeobjects)
    						{
    							
    							freeobj->X = swapsignedword(*(xindex));
    							freeobj->Y = swapsignedword(*(xindex+1)) & 0xFFF;
    							freeobj->Render= rotl(freeobj->Y, 2) & 3;
    							freeobj->Status = freeobj->Render;
    							int respawn=((swapendianword(*(xindex+2))&0xFF00)>>8);
    							if (respawn <= 0)
    							{
    								respawn=respawn & 0x7F;
    								freeobj->RespawnNo = oldstate;
    							}
    							freeobj->ID=respawn;
    							int subtype=(swapsignedword(*(xindex+2))&0x00FF);							
    							freeobj->Subtype = subtype;
    						}
    					}
                    }
                    //xindex=xindex-3;
                    //statusindex=statusindex-3;
                    
					//xpos=((signed short)swapsignedword(*(xindex-3)));  //grab x pos of previous obj
                    //status=((swapsignedword(*(statusindex-3)) & 0xFF00)>>8);  


                }    //loc_D9BC+4
			}
            
			
			//loc_D9C6
			if ( (swapendianword(*(xindex+2)) & 0x00FF) < 0 ) //if the last object to be left off on has respawn bit
				objleftcount=objleftcount+1;
			
			//loc_D9D0
			xindex=xindex+3;
    
			//loc_D9D0
			v_opl_datax2=xindex;  //1 object before pbject left off on
			xindex=v_opl_datax1;  //reverse 1st x location buffer
			statusindex=xindex+2;
            xpos=((signed short)swapsignedword(*(xindex-3)));  //grab x pos of previous obj
            status=((swapsignedword(*(statusindex-3)) & 0xFF00)>>8);  
            
            temp=temp+768; //cur loc = 1/5 screens to left + 2 1/5 screens to right = 2 screens to right
			
			//loc_D9DE
			//CMP XPOS, TEMP: BGT SKIPPASTCODE | IF TEMP > XPOS THEN SKIPPASTCODE | IF TEMP <= XPOS THEN DO CODE | IF XPOS > TEMP THEN DO CODE 

			while (xpos > temp) //for objects
			{
                  
				if (status <= 0) //if respawn bit then
					objrightcount=objrightcount-1;
				//loc_D9EC
                xindex = xindex-3;
			    statusindex=statusindex-3;
                xpos=((signed short)swapsignedword(*(xindex-3)));  //grab x pos of previous obj
                status=((swapsignedword(*(statusindex-3)) & 0xFF00)>>8);  
            }
			
			v_opl_datax1=xindex;  //last object to the left of screen
		}
		else if (v_opl_screen < temp)       //INITIAL CASE (V_OPL_SCREEN:-1 < TEMP:v_screenposx:0) or if screen has since moved right 
		{
            v_opl_screen=temp;
              
			
            //*movea.l (v_opl_data),a0, aka index=0
			temp=temp+640;		 	//move 2 screens in to the right
			bool freeobjects=false;
			word *xindex=v_opl_datax1;  //working with the 
			word *statusindex=xindex+2;
            signed short xpos=(swapsignedword(*(xindex)));  //grab x pos of previous obj
            signed char status=((swapsignedword(*(statusindex)) & 0xFF00)>>8);  
			
			do                        //loc_DA02
			{
                if (xpos == 0xFFFF) { xpos = -1; }
                //CMP XPOS, TEMP: BLS SKIPPASTCODE | IF TEMP <= XPOS THEN SKIPPASTCODE | IF TEMP > XPOS THEN DO CODE | IF XPOS <= TEMP THEN DO CODE 

                if (xpos <= temp) 
                {   //if object less than 2 screens ahead then (objects at current screen and a screen ahead)
				
                	if (status <= 0) //if this object has the respawn bit
    				{
        
    					oldstate=objrightcount; //objstatecount = object number
    					objrightcount=objrightcount+1;                           //add to count (objstate count account for objects with respawn bit to the right of screen)
                    }
    			
                    //bsr locDA3C
    				//=============loc_DA3C==============
    				bool skip=false;
    				if (status <= 0) //if this object has the respawn bit
    				{
                        byte zcode=(objstate[oldstate] & 128) >> 7;
    					objstate[oldstate] = objstate[oldstate] | 128; //set bit 8 (respawn bit) of object state buffer, oldstate refers to original object we are working with
    					if (zcode != 0)                     //if respawn was previously set  
    					{                             
    						xindex=xindex+3;          //shift this back to pointing to the 2nd
    						statusindex=statusindex+3;
    						xpos=((signed short)swapsignedword(*(xindex)));  //grab x pos of previous obj
                            status=((swapsignedword(*(statusindex)) & 0xFF00)>>8);  
    						
                            skip=true;
    					}
    						
    				}
    				
    				if (skip==false)
    				{
                        
    					object *freeobj;
    					
    					freeobj=FindFreeObj();           
    					freeobjects=freeObjects();
    						
    					//OPL_MakeItem
    					if (freeobjects)
    					{
    							
    						freeobj->X = swapsignedword(*(xindex));
    						freeobj->Y = swapsignedword(*(xindex+1)) & 0xFFF;
    						freeobj->Render = rotl(freeobj->Y, 2) & 3;
    						freeobj->Status = freeobj->Render;
    						unsigned short respawn=( ( swapendianword(*(xindex+2)) & 0xFF00 ) >> 8 );
    						if (respawn <= 0)
    						{
    							respawn=respawn & 0x7F;
    							freeobj->RespawnNo = oldstate;
    						}
    						freeobj->ID=respawn;
    						if (freeobj->empty()) { freeobjects=false; }
    						////printf("freeobj->ID=%i\n",freeobj->ID);
    						int subtype=( swapendianword(*(xindex+2)) & 0x00FF );							
    						freeobj->Subtype = subtype;
    					}
    					xindex=xindex+3;
    			        statusindex=statusindex+3;
                        xpos=((signed short)swapsignedword(*(xindex)));  //grab x pos of previous obj
                        status=((swapsignedword(*(statusindex)) & 0xFF00)>>8);  
    				} 
                }
			
            } while (freeobjects && xpos <= temp);  //loc_DA14
			
			v_opl_datax1=xindex; //should point to 
			xindex=v_opl_datax2;
			statusindex=xindex+2;
			xpos=((signed short)swapsignedword(*(xindex)));  //grab x pos of previous obj
            status=((swapsignedword(*(statusindex)) & 0xFF00)>>8);  
			
			//additional objects
			temp=temp-768;          //2 & 2/5th screens back (from 2 in) leaving 2/5th back from left to compare
			
			if (temp > 0)           //if screen greater than this 2/5s in
			{
                //CMP XPOS, TEMP: BLS SKIPPASTCODE | IF TEMP <= XPOS THEN SKIPPASTCODE | IF TEMP > XPOS THEN DO CODE | IF XPOS <= TEMP THEN DO CODE 

				while (xpos <= temp)         //for all objects more than 2/5 screens to the left
				{
					if (status <= 0)
						objleftcount=objleftcount+1;                 //add to objects to the left
					xindex=xindex+3;
					statusindex=statusindex+3;
					xpos=((signed short)swapsignedword(*(xindex)));  //grab x pos of next obj
                    status=((swapsignedword(*(statusindex)) & 0xFF00)>>8);  
				}
			}
			v_opl_datax2=xindex;                                 //update this pointer (can go no more to the right now)
		}
	  }
    //printf("objleftcount: %i\n",objleftcount);
    //printf("objrightcount: %i\n",objrightcount);
}
			
			
object *FindFreeObj()
{
       
	int index = 32;
	int count = 95;
    obfree=false;
	for (int lp=0; lp<count; lp++)
	{
                ////printf("objects[%i].ID=%i", lp+index, objects[lp+index].ID);
		if (objects[lp+index].empty())
		{
            
            obfree=true;
            return &(objects[lp+index]);
        }
    }
    
}

bool freeObjects() { return obfree; }

//===============level object positions==============//


unsigned char ghz1[] = {
0x01,0x44,0x03,0x60,0xa5,0x12,0x02,0x48,0x03,0x51,0xa6,0x06,0x03,0x34,0x02,
0x2c,0xa5,0x45,0x03,0x34,0x03,0x28,0x41,0x02,0x03,0x40,0x03,0xac,0xc0,0x00,
0x04,0x20,0x03,0x30,0xa2,0x00,0x04,0x30,0x43,0x78,0x1c,0x03,0x04,0x6c,0x03,
0x20,0xa5,0x14,0x04,0xa0,0x04,0x60,0xab,0x00,0x04,0xa8,0x03,0x88,0x49,0x00,
0x04,0xa8,0x03,0x88,0x11,0x0c,0x05,0x10,0x03,0x78,0x1c,0x03,0x05,0xd6,0x03,
0x20,0xa6,0x05,0x06,0x80,0x03,0x87,0xa5,0x10,0x06,0xa0,0x03,0x97,0xa5,0x10,
0x06,0xc0,0x03,0xa5,0xa5,0x10,0x06,0xe3,0x03,0xb0,0xa5,0x10,0x07,0x0b,0x03,
0xb3,0xa5,0x10,0x07,0x37,0x03,0xaf,0xa5,0x10,0x07,0x5b,0x03,0x92,0xa5,0x10,
0x08,0xb0,0x03,0x50,0x9f,0x00,0x09,0x60,0x02,0xfa,0x9f,0x00,0x09,0xc4,0x02,
0xc0,0xa5,0x11,0x09,0xcd,0x02,0xfd,0x3b,0x00,0x0a,0x30,0x43,0x08,0x1c,0x03,
0x0a,0x78,0x04,0x00,0xab,0x00,0x0a,0xa8,0x03,0x18,0x49,0x00,0x0a,0xa8,0x03,
0x18,0x11,0x0c,0x0a,0xc8,0x03,0xc0,0xab,0x00,0x0b,0x10,0x03,0x08,0x1c,0x03,
0x0b,0x94,0x02,0xd0,0xa5,0x11,0x0b,0xa0,0x02,0xfe,0x3b,0x00,0x0c,0x08,0x02,
0xf8,0x44,0x00,0x0c,0x50,0x03,0x4c,0xc0,0x00,0x0d,0x08,0x03,0xb0,0x44,0x00,
0x0d,0x08,0x03,0xe0,0x44,0x01,0x0d,0x28,0x03,0x73,0x36,0x00,0x0d,0x40,0x02,
0x68,0xa2,0x00,0x0d,0x50,0x02,0xb6,0xa5,0x10,0x0d,0x58,0x03,0x76,0x36,0x00,
0x0d,0x70,0x02,0xa9,0xa5,0x10,0x0d,0x88,0x03,0x77,0x36,0x00,0x0d,0x92,0x02,
0x97,0xa5,0x10,0x0d,0xb0,0x03,0x7b,0x41,0x02,0x0d,0xb4,0x02,0x87,0xa5,0x10,
0x0d,0xd0,0x02,0x70,0xa2,0x00,0x0d,0xd8,0x03,0x70,0x36,0x00,0x0d,0xda,0x02,
0x77,0xa5,0x10,0x0e,0x2c,0x02,0x78,0x41,0x02,0x0e,0xb1,0x02,0x11,0xa5,0x10,
0x0e,0xd0,0x02,0x40,0x9a,0x00,0x0e,0xd2,0x02,0x0a,0xa5,0x10,0x0e,0xf5,0x02,
0x03,0xa5,0x10,0x0f,0x1a,0x02,0x05,0xa5,0x10,0x0f,0x3f,0x02,0x09,0xa5,0x10,
0x0f,0x48,0x02,0x90,0x36,0x20,0x0f,0x56,0x03,0xb3,0x36,0x00,0x0f,0x58,0x02,
0x8f,0x36,0x20,0x0f,0x66,0x02,0x08,0xa5,0x10,0x0f,0x68,0x02,0x8c,0x36,0x20,
0x0f,0x78,0x02,0x87,0x36,0x20,0x0f,0x80,0x03,0xbf,0x41,0x02,0x0f,0x88,0x02,
0xd8,0xa5,0x12,0x0f,0xa0,0x02,0x01,0x3b,0x00,0x0f,0xac,0x03,0xb7,0x36,0x00,
0x0f,0xd8,0x02,0x72,0x3b,0x00,0x10,0x30,0x42,0xb0,0x9a,0x01,0x10,0xa0,0x02,
0xb0,0x9a,0x00,0x11,0x00,0x01,0xd0,0xa2,0x00,0x11,0x58,0x03,0x2c,0xa5,0x12,
0x11,0x70,0x03,0x77,0x36,0x00,0x11,0xd4,0x03,0x70,0x36,0x00,0x11,0xe8,0x02,
0x2c,0xf9,0x01,0x12,0x20,0x01,0xe8,0x18,0x01,0x12,0x20,0x03,0x2c,0xa5,0x12,
0x12,0x34,0x03,0x73,0x36,0x00,0x12,0x5c,0x02,0x3e,0xa5,0x10,0x12,0x60,0x01,
0xa8,0x18,0x05,0x12,0x80,0x02,0x49,0xa5,0x10,0x12,0xa2,0x02,0x59,0xa5,0x10,
0x12,0xc0,0x03,0x30,0xa6,0x06,0x12,0xc3,0x02,0x69,0xa5,0x10,0x12,0xe0,0x03,
0x30,0xa6,0x06,0x12,0xea,0x02,0x71,0xa5,0x10,0x12,0xf8,0x02,0x38,0xc2,0x00,
0x13,0x00,0x03,0x30,0xa6,0x06,0x13,0x08,0x01,0x70,0xa6,0x06,0x13,0x20,0x03,
0x30,0xa6,0x05,0x13,0xa0,0x01,0x30,0xa2,0x00,0x13,0xa0,0x01,0x88,0x18,0x03,
0x14,0x20,0x01,0xa8,0x18,0x03,0x14,0x48,0x03,0x04,0xc0,0x00,0x14,0xa0,0x01,
0xc8,0x18,0x03,0x14,0xd0,0x03,0x34,0x36,0x00,0x15,0x00,0x03,0x31,0x36,0x00,
0x15,0x10,0x01,0x7c,0xa2,0x00,0x15,0x30,0x03,0x30,0x36,0x00,0x15,0x3c,0x02,
0x60,0xa5,0x10,0x15,0x4e,0x02,0x30,0xa5,0x10,0x15,0x80,0x01,0xf1,0xa6,0x04,
0x15,0x80,0x02,0x1d,0xa5,0x10,0x15,0xaf,0x02,0x30,0xa5,0x10,0x15,0xc3,0x02,
0x60,0xa5,0x10,0x16,0x10,0x01,0x30,0xa2,0x00,0x16,0x20,0x01,0x60,0x18,0x06,
0x16,0x60,0x01,0xe8,0x18,0x02,0x16,0x90,0x00,0xe0,0x18,0x02,0x16,0xe4,0x01,
0xb5,0xa5,0x10,0x17,0x0c,0x01,0xb5,0xa5,0x10,0x17,0x34,0x01,0xab,0xa5,0x10,
0x17,0x40,0x00,0xa0,0x18,0x01,0x17,0x5b,0x01,0x9c,0xa5,0x10,0x17,0x84,0x01,
0x89,0xa5,0x10,0x17,0xa6,0x01,0x79,0xa5,0x10,0x17,0xe0,0x01,0x74,0xa5,0x10,
0x18,0x08,0x01,0xc0,0x44,0x01,0x18,0x08,0x01,0xf0,0x44,0x01,0x18,0x0c,0x01,
0x74,0xa5,0x10,0x18,0x20,0x00,0x74,0xa5,0x16,0x18,0x3c,0x01,0x76,0xa5,0x10,
0x18,0x6c,0x01,0x78,0xa5,0x10,0x18,0x80,0x41,0x38,0xc2,0x00,0x18,0x9c,0x01,
0x7a,0xa5,0x10,0x18,0xc8,0x00,0x74,0xa5,0x16,0x18,0xcc,0x01,0x74,0xa5,0x10,
0x18,0xfc,0x01,0x74,0xa5,0x10,0x19,0x00,0x41,0x40,0xc2,0x00,0x19,0x2c,0x01,
0x75,0xa5,0x10,0x19,0x40,0x41,0x38,0xc2,0x00,0x19,0x50,0x03,0x70,0xa5,0x14,
0x19,0x5c,0x01,0x7a,0xa5,0x10,0x19,0x70,0x00,0x74,0xa5,0x15,0x19,0x80,0x41,
0x60,0xc2,0x00,0x19,0x80,0x03,0x73,0xf9,0x02,0x19,0x8c,0x01,0x7b,0xa5,0x10,
0x19,0xbc,0x01,0x76,0xa5,0x10,0x19,0xec,0x01,0x74,0xa5,0x10,0x1a,0xf8,0x00,
0xc0,0x44,0x02,0x1a,0xf8,0x00,0xe0,0x44,0x02,0x1a,0xf8,0x02,0xb0,0x44,0x02,
0x1a,0xf8,0x02,0xf0,0x44,0x02,0x1b,0x60,0x00,0x88,0x18,0x03,0x1b,0x70,0x02,
0x88,0x18,0x03,0x1b,0xa0,0x00,0xc8,0x18,0x03,0x1b,0xe0,0x01,0x08,0x18,0x03,
0x1c,0x00,0x42,0xc0,0xa2,0x00,0x1c,0x20,0x01,0x48,0x18,0x03,0x1c,0x60,0x01,
0x88,0x18,0x03,0x1c,0xa0,0x01,0xc8,0x18,0x03,0x1c,0xe0,0x02,0x08,0x18,0x03,
0x1d,0x40,0x02,0x08,0x18,0x03,0x1d,0x58,0x02,0x68,0xa5,0x16,0x1d,0x64,0x02,
0x58,0xa5,0x16,0x1d,0x70,0x02,0x48,0xa5,0x15,0x1d,0x78,0x04,0x76,0x3b,0x00,
0x1d,0x7c,0x02,0x38,0xa5,0x14,0x1d,0x88,0x02,0x28,0xa5,0x13,0x1d,0xa0,0x03,
0x20,0xa2,0x00,0x1d,0xe0,0x02,0x04,0x18,0x01,0x1d,0xf8,0x04,0xb0,0x44,0x02,
0x1e,0x00,0x02,0x68,0xa5,0x10,0x1e,0x08,0x03,0x70,0x44,0x00,0x1e,0x18,0x43,
0x68,0xc2,0x01,0x1e,0x20,0x04,0xb4,0x36,0x00,0x1e,0x40,0x44,0x50,0xc2,0x01,
0x1e,0x48,0x03,0x40,0x44,0x00,0x1e,0x60,0x43,0x30,0xc2,0x01,0x1e,0x60,0x44,
0x30,0xc2,0x01,0x1e,0xa0,0x02,0xa0,0xa2,0x00,0x1e,0xd8,0x02,0xff,0x3b,0x00,
0x1f,0x30,0x43,0x08,0x1c,0x03,0x1f,0x64,0x04,0x80,0xa5,0x15,0x1f,0x70,0x02,
0xb4,0xa5,0x14,0x1f,0x80,0x03,0xc0,0xab,0x00,0x1f,0xa8,0x03,0x18,0x49,0x00,
0x1f,0xa8,0x03,0x18,0x11,0x0c,0x1f,0xc0,0x03,0xd0,0xab,0x00,0x20,0x10,0x03,
0x0a,0x1c,0x03,0x20,0x20,0x04,0xb0,0x36,0x00,0x20,0x48,0x03,0x90,0x36,0x20,
0x20,0x58,0x03,0x8e,0x36,0x20,0x20,0x68,0x03,0x8b,0x36,0x20,0x20,0x78,0x03,
0x86,0x36,0x20,0x20,0x80,0x03,0x50,0xc2,0x00,0x20,0x88,0x03,0x82,0x36,0x20,
0x20,0xd0,0x03,0x70,0x3b,0x00,0x21,0x35,0x03,0x74,0xa5,0x10,0x21,0x58,0x03,
0x7d,0xa5,0x10,0x21,0x7a,0x03,0x88,0xa5,0x10,0x21,0x80,0x04,0x8c,0x9f,0x00,
0x21,0x9c,0x03,0x97,0xa5,0x10,0x21,0xbe,0x03,0xa8,0xa5,0x10,0x21,0xe2,0x03,
0xb1,0xa5,0x10,0x22,0x48,0x03,0x50,0xa6,0x06,0x23,0x34,0x03,0x20,0xa6,0x06,
0x23,0x42,0x04,0x75,0xa5,0x10,0x23,0x67,0x04,0x7e,0xa5,0x10,0x23,0x78,0x04,
0x08,0x18,0x02,0x23,0x86,0x04,0x8d,0xa5,0x10,0x23,0xa5,0x04,0x9d,0xa5,0x10,
0x23,0xc6,0x04,0xae,0xa5,0x10,0x23,0xec,0x04,0xb6,0xa5,0x10,0x23,0xf0,0x03,
0x80,0xa2,0x00,0x24,0x14,0x04,0xb6,0xa5,0x10,0x24,0x3a,0x04,0xb6,0xa5,0x10,
0x24,0x61,0x04,0xb6,0xa5,0x10,0x24,0x86,0x04,0xb5,0xa5,0x10,0x25,0x60,0x04,
0xa2,0x0d,0x00,0x25,0x84,0x04,0x60,0x7d,0x03,0x25,0x84,0x04,0x78,0x7d,0x03,
0x25,0x84,0x04,0x90,0x7d,0x03,0x25,0xa8,0x04,0x50,0x4b,0x00,0x25,0xd4,0x04,
0x50,0x7d,0x01,0x25,0xd4,0x04,0x70,0x7d,0x02,0xff,0xff,0x00,0x00,0x00,0x00
};

void pcObjects()
{
     unsigned char index=0;
     
     
     objnew(ghz1)
     ////printf ("\nghz=%p\n",ghz1);
     for (int lp=0; lp<127; lp++)
         objects[lp].init(0);
     v_screenposx=0;
     
     
}
					
					
			
			
			
		
	
	
	
	
	
	
	
	
	
